package ee.videorental.serverside;

import java.util.ArrayList;

public class ActiveSessions
{
	private static ActiveSessions instance = null;
	private ArrayList<ClientSession> sessionList 
		= new ArrayList<ClientSession>();
	
	private ActiveSessions()
	{
		
	}
	
	public static ActiveSessions getInstance() 
	{
		if (instance == null)
		{
			instance = new ActiveSessions();
		}
		return instance;
	}
	
	public void addSession(ClientSession newClient) 
	{
		synchronized (sessionList)
		{
			sessionList.add(newClient);
			System.out.println("Saabus uus klient " + newClient);
			sessionList.notifyAll();
		}
	}
	
	public boolean getIsActiveSessionEmpty()
	{
		synchronized (sessionList) 
		{
			return sessionList.isEmpty();
		}
	}
	
	public ArrayList<ClientSession> getClientSessionList()
	{
		synchronized (sessionList)
		{
			return this.sessionList;  
		}
	}
}